//
//  NYLearnRecordViewController.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/22.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYLearnRecordViewController.h"
#import "NYDetailContentViewController.h"

//views
#import "NYLearnRecordCell.h"

//models
#import "NYCourseModel.h"

@interface NYLearnRecordViewController () <QMUITableViewDelegate>

//@property (nonatomic, strong) NSMutableArray *recordMutaArray;

@end

@implementation NYLearnRecordViewController

#pragma mark - Life Cycle Methods
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
}
#pragma mark - Intial Methods
- (void)initTableView {
    [super initTableView];

}
- (void)configNimbus {
    [super configNimbus];
    
    self.tableViewModel.delegate = self;
    @weakify(self);
    [self.tableViewActions attachToClass:[NYCourseModel class] tapBlock:^BOOL(NYCourseModel *object, id target, NSIndexPath *indexPath) {
        
        @strongify(self);
        
        NSMutableDictionary *paraDictionary = nil;
        NSDictionary *paraDict = nil;
        NYExamineRequestStatus status = NYExamineRequestStatusChoose;
        if (object.cup_name.length > 0) {
            status = NYExamineRequestStatusCup;
            
            paraDict = @{kRequestKeyChannel:@(NYUserManager.channelID), kRequestKeyLoginCode : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.logincode), kRequestKeyUser_ID:NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.user_id), kRequestKeyCupID :NOT_NULL_STRING_DEFAULT_EMPTY(@(object.id).stringValue)};
        } else {
            status = NYExamineRequestStatusChoose;
            paraDict = @{kRequestKeyChannel:@(NYUserManager.channelID), kRequestKeyLoginCode : NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.logincode), kRequestKeyUser_ID:NOT_NULL_STRING_DEFAULT_EMPTY(NYUserManager.user_id), kRequestKeyCourseID :NOT_NULL_STRING_DEFAULT_EMPTY(@(object.id).stringValue)};
        }
        
        paraDictionary = [NSMutableDictionary dictionaryWithDictionary:paraDict];
        
        NYVideoModel *videoModel = object.currentPlayModel;

        [paraDictionary setObject:@(videoModel.id).stringValue forKey:kRequestVideoID];
        
        NYDetailContentViewController *ViewController = [[NYDetailContentViewController alloc] initWithParaDictionary:paraDictionary withDeatilModel:object preparePlayModel:videoModel preparePlayModelIndex:object.currentPlayIndex examineStatus:status];
        [self.navigationController pushViewController:ViewController animated:true];

        return true;
    }];

}
#pragma mark - Network Methods
- (void)loadData {
    
    [self configNimbus];
    
    [self setLoading:YES animation:YES];
    
    [self.tableViewModel removeAll];
//    [self.recordMutaArray removeAllObjects];
    
    NSMutableDictionary *recordDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:APP_LEARNING_RECORD_PATH];
    NSMutableDictionary *userDictionary = recordDictionary[NYUserManager.user_id];
    NSArray *arrayM = userDictionary[@(NYUserManager.channelID).stringValue];
//    [self.recordMutaArray addObjectsFromArray:arrayM];
    
    [self.tableViewModel addObjectsFromArray:arrayM];
    [self.tableView reloadData];
    [self setSuccess];
}
#pragma mark - Target Methods

#pragma mark - Public Methods
- (void)configNavigationBar:(BaseNavigationBar *)navigationBar {
    [super configNavigationBar:navigationBar];
    self.title = @"学习记录";
}
+ (NYViewControllerNavigationBarType)navigationBarType {
    
    return NYViewControllerNavigationBarTypeBlue;
}

#pragma mark - Private Method

#pragma mark - External Delegate

#pragma mark - Setter Getter Methods
//- (NSMutableArray *)recordMutaArray {
//    if (!_recordMutaArray) {
//
//        _recordMutaArray = [NSMutableArray array];
//    }
//    return _recordMutaArray;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
